/*
Title:
	LCD Wrapper
Module:
    Loop & Setup    
Date:	
	4th July 2013
Hardware:
	Arduino UNO R3 - AtMega328P @ 16Mhz
IDE:
	Atmel Studio 6.1
Description:
	A test to see if my new LCD Wrapper Class works
Expected Output:  
	1) As per the cLcdHandler class
History:
	04/07/13 Created	   
Notes:
	"LCDKeypad.cpp" & "LCDKeypad.h" files were added to Arduino Library.
	These files came with the demo code supplied with the LCD Keypad website.
*/
 
// Core Arduino Libraries
#include "Arduino.h"
// LCD Wrapper Class
#include "LCD Handler/cLcdHandler.h"
#include "Arduino Libraries/TLC5940/Tlc5940.h"

// Define the main Arduino methods for use
void setup();
void loop();

// Define the "C" functions here
#ifdef __cplusplus
extern "C" {
#endif
	void me_SetupTimer( );
#ifdef __cplusplus
}
#endif

// Global Variables
//int16_t led = 13; // Pin 13 has an LED connected on most Arduino boards.
//bool led_on = true; // Boolean to track state of flashing LED
//uint16_t count = 0; // Delay for flashing the LED


extern boolean at_PwmTick;
extern boolean at_LedTick;

// Wrapper Object
cLcdHandler cl_LCD;
cTLC5940 cl_TLC5940;
//uint8_t at_IdDebug1, at_IdDebug2;
uint16_t at_LedPattern = 0x0001;
// ---------------------------------------------------------------------------
// The setup routine runs once when you press reset:
// ---------------------------------------------------------------------------
void setup() 
{
	pinMode(A1, INPUT); // Light Sensor
	pinMode(A2, INPUT); // Temp/Humid Sensor
	pinMode(A3, OUTPUT); // XLAT TLC5940
	pinMode(A4, OUTPUT); // Slave Select 2
	pinMode(A5, OUTPUT); // Slave Select 1
	digitalWrite(A4, LOW);
	digitalWrite(A5, LOW);
	
	me_SetupTimer( );
	
    // Initialize the digital pin as an output.
    //pinMode(led, OUTPUT);     
  
    //at_IdDebug1 = cl_LCD.me_AddEntry("Debug 1", 1000, "11111111");
    //at_IdDebug2 = cl_LCD.me_AddEntry("Debug 2", 1000, "22222222");
    
    //cl_LCD.me_ShowEntry(at_IdDebug1, 0);
    //cl_LCD.me_ShowEntry(at_IdDebug2, 1);
}

// ---------------------------------------------------------------------------
// The loop routine runs over and over again forever:
// ---------------------------------------------------------------------------
void loop() 
{
/*
	count++;
	
	if (count >= 20) // This creates a 50ms * 20 delay = 1 second for flashing LED
	{
		count = 0; // Reset delay count
		digitalWrite(led, led_on); // Flash LED
		led_on = !led_on; // Toggle LED state for next time
        
        if (led_on)
        {
            cl_LCD.me_UpdateEntry(at_IdDebug1, "1111!ON!1111");
            cl_LCD.me_UpdateEntry(at_IdDebug2, "2222!ON!2222");
        }
        else
        {
            cl_LCD.me_UpdateEntry(at_IdDebug1, "1111!OFF!1111");
            cl_LCD.me_UpdateEntry(at_IdDebug2, "2222!OFF!2222");
        }                        
	} // else not time yet
	
	delay(50); // Wait for 50ms
    
    cl_LCD.me_LcdTick( );
*/
	if (at_PwmTick)	
	{
		at_PwmTick = false;
		cl_TLC5940.me_PwmTick();
	}
	
	if (at_LedTick)
	{
		//at_LedTick = false;
		//cl_TLC5940.me_SetPins(at_LedPattern);
		//cl_TLC5940.me_UpdateOutput();
		//at_LedPattern <<= 1;
		//if (at_LedPattern == 0x0000)
		//{
	//		at_LedPattern = 0x0001;
//		}
	}
}
// ---------------------------------------------------------------------------
